package dao.impl;

import dao.CallTimeDao;
import domain.CallTime;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import util.JDBCUtils;

import java.util.List;

public class CallTimeDaoImpl implements CallTimeDao {
    private JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());

    //用户每日通话时长
    @Override
    public List<CallTime> SelectDurationByTelephoneAndDate(String telephone, int year, int month) {
        String sql = "SELECT A.call_duration_sum,C.day FROM tb_call A LEFT JOIN tb_contacts B ON A.id_contact = B.id LEFT JOIN tb_dimension_date C ON A.id_date_dimension = C.id WHERE B.telephone = "+telephone+" AND C.year = "+year+" AND C.month = "+month+" AND C.day != -1 ORDER BY day ";
        List<CallTime> contacts = template.query(sql, new BeanPropertyRowMapper<CallTime>(CallTime.class));
        return contacts;
    }



}
